*************************************************************;
* survey analysis                                           *;
*************************************************************;

*get data for the survey;
PROC IMPORT OUT= WORK.one 
            DATAFILE= "C:\survey2022_23_dat.txt" /*change path*/
            DBMS=TAB REPLACE;
     GETNAMES=YES;
     DATAROW=2; 
RUN;

data surv2;
   set surv;
run;

proc print data=surv2;
run;

proc freq data=surv;
tables randomization group;
run;
proc freq data=surv;
   tables (TSq1 TSq2 TSq3 TSq4 TSq5 TSq6 EMq1 EMq2 EMq3 EMq4 EMq5 EMq6 EMq7 EMq8 EMq9 EMq10)*randomization;
run;
******************;
*initial survey;
******************;

data survey1T;
   set surv2;
   if randomization='Traditional';
   q1=TSq1; *What type of learning format for the Design of Medial Health Studies course do you prefer?;
   q2=TSq2; *Were the learning objectives clear? ;
   q3=TSq3; *How many times did you go through the material;
   q4_5=TSq4;*How much did the questions throughout the e-module increase your understanding of the material;
   q5_6=TSq5;*Did you find the video engaging;
   q6_7=TSq6; *How much did the video increase your confidence ;
   keep q1 q2 q3 q4_5 q5_6 q6_7 age gender race Year group randomization id ;
run;
data survey1E;
   set surv2;
   if randomization='Emodule';
   q1=EMq1; *What type of learning format for the Design of Medial Health Studies course do you prefer?;
   q2=EMq2; *Were the learning objectives clear? ;
   q3=EMq3; *How many times did you go through the material;
   q4_5=EMq5;*How much did the questions throughout the e-module increase your understanding of the material;
   q5_6=EMq6;*Did you find the video engaging;
   q6_7=EMq7; *How much did the video increase your confidence ;
   keep q1 q2 q3 q4_5 q5_6 q6_7 EMq4 EMq8 age gender race Year group randomization id ;     
run;

proc format; 
   value q1f 1='Interactive E-module'
             2='Other';
   value q4f 1='The same'
			 2='A little change' 
			 3='To some extent'
			 4='A lot';
   value q5f 1='Not engaging'
             2='Minimal engagement'
			 3='Somewhat engaging' 
			 4='Engaging'
			 5='Very engaging';
   value q6f 1='Not at all'
             2='The same'
			 3='A little'
			 4='To some extent'
			 5='A lot';
data survey1;
   set survey1T survey1E;
   *remove those that did not fill out the initial survey;
   if q1=' ' then delete;

   if q1='Interactive E-module' then q1cat=1;
   else q1cat=2;

   if q3=1 then q3cat='1  ';
   else if q3 gt 1 then q3cat='>1';

*recode so the categories are in the correct order;
   if q4_5='The same' then q4_5cat=1;
   else if q4_5='A little change' then q4_5cat=2;
   else if q4_5='To some extent' then q4_5cat=3;
   else if q4_5='A lot' then q4_5cat=4;

   if q5_6='Not engaging' then q5_6cat=1;
   else if q5_6='Minimal engagement' then  q5_6cat=2;
   else if q5_6='Somewhat engaging' then  q5_6cat=3;
   else if q5_6='Engaging' then  q5_6cat=4;
   else if q5_6='Very engaging' then  q5_6cat=5;

   if q6_7='Not at all' then q6_7cat=1;
   else if q6_7='The same' then  q6_7cat=2;
   else if q6_7='A little' then  q6_7cat=3;
   else if q6_7='To some extent' then  q6_7cat=4;
   else if q6_7='A lot' then  q6_7cat=5;

   if race='Asian' then racecat='Asian'; 
   else if race='Black or African American' then racecat='Black';
   else if race in('Hispanic, Latino, Spanish Origin','Hispanic\, Latino\, Spanish Origin','White, Hispanic, Latino, Spanish Origin') then racecat='Hispanic';
   else if race='White' then racecat='White';
   else if race in('Black or African American, Asian','White,Asian') then racecat='Multiple';
   else if race='Other' or race='Prefer not to answer' then racecat='UNK';

   format q4_5cat q4f. q5_6cat q5f. q1cat q1f. q6_7cat q6f. ;
run;
proc print data=survey1;
run;

proc means data=survey1 n mean median std;
class randomization;
var age;
run;
proc ttest data=survey1 ;
class randomization;
var age;
run;
proc freq data=survey1;
exact fisher;
tables (gender  racecat)*randomization/chisq;
run;
proc freq data=survey1;
exact fisher;
tables (gender  race)*randomization;
run;
options nodate nonumber missing=' ';
ods rtf file="C:\surv1.rtf" style=nostyle bodytitle;
proc freq data=survey1;
exact fisher;
tables (q1 q1cat q2 q3cat q4_5cat q5_6cat q6_7cat EMq4 EMq8 )*randomization/chisq nopercent norow;
run;
ods rtf close;

*****************************;
* second survey             *;
*****************************;

data survey2E;
   set surv2;
   if randomization='Emodule';
   q1=TSq1; *What type of learning format for the Design of Medial Health Studies course do you prefer?;
   q2=TSq2; *Were the learning objectives clear? ;
   q3=TSq3; *How many times did you go through the material;
   q4_5=TSq4;*How much did the questions throughout the e-module increase your understanding of the material;
   q5_6=TSq5;*Did you find the video engaging;
   q6_7=TSq6; *How much did the video increase your confidence ;
   keep q1 q2 q3 q4_5 q5_6 q6_7 age gender race Year group ID randomization  ;
run;
data survey2T;
   set surv2;
   if randomization='Traditional';
   q1=EMq1; *What type of learning format for the Design of Medial Health Studies course do you prefer?;
   q2=EMq2; *Were the learning objectives clear? ;
   q3=EMq3; *How many times did you go through the material;
   q4_5=EMq5;*How much did the questions throughout the e-module increase your understanding of the material;
   q5_6=EMq6;*Did you find the video engaging;
   q6_7=EMq7; *How much did the video increase your confidence ;
   keep q1 q2 q3 q4_5 q5_6 q6_7 EMq4 EMq8 age gender race Year group ID randomization  ;     
run;

proc format; 
   value q1f 1='Interactive E-module'
             2='Other';
   value q4f 1='The same'
			 2='A little change' 
			 3='To some extent'
			 4='A lot';
   value q5f 1='Not engaging'
             2='Minimal engagement'
			 3='Somewhat engaging' 
			 4='Engaging'
			 5='Very engaging';
data survey2;
   set survey2T survey2E;
   *delete those that didn't complete survey 2;
   if q1=' ' then delete;

   if q1='Interactive E-module' then q1cat=1;
   else q1cat=2;

   if q3=1 then q3cat='1  ';
   else if q3 gt 1 then q3cat='>1';

   if q4_5='The same' then q4_5cat=1;
   else if q4_5='A little change' then q4_5cat=2;
   else if q4_5='To some extent' then q4_5cat=3;
   else if q4_5='A lot' then q4_5cat=4;

   if q5_6='Not engaging' then q5_6cat=1;
   else if q5_6='Minimal engagement' then  q5_6cat=2;
   else if q5_6='Somewhat engaging' then  q5_6cat=3;
   else if q5_6='Engaging' then  q5_6cat=4;
   else if q5_6='Very engaging' then  q5_6cat=5;

   if q6_7='Not at all' then q6_7cat=1;
   else if q6_7='The same' then  q6_7cat=2;
   else if q6_7='A little' then  q6_7cat=3;
   else if q6_7='To some extent' then  q6_7cat=4;
   else if q6_7='A lot' then  q6_7cat=5;

   if race='Asian' then racecat='Asian';
   else if race='White' then racecat='White';
   else if race='Black or African American' then racecat='Black';
   else if race in('Hispanic, Latino, Spanish Origin','White, Hispanic, Latino, Spanish Origin') then racecat='Hispanic';
   else if race in('Black or African American, Asian','White,Asian') then racecat='Multiple';
   else if race='Other' or race='Prefer not to answer' then racecat='UNK';

   format q4_5cat q4f. q5_6cat q5f. q1cat q1f. q6_7cat q6f. ;
run;
proc means data=survey2 n mean median std;
class randomization;
var age;
run;
proc ttest data=survey2 ;
class randomization;
var age;
run;
proc freq data=survey2;
exact fisher;
tables (gender  race )*randomization/chisq;
run;
proc freq data=survey2;
tables race ;
run;
options nodate nonumber missing=' ';
ods rtf file="C:\surv2.rtf" style=nostyle bodytitle;
proc freq data=survey2;
exact fisher;
tables (q1 q1cat q2 q3cat q4_5cat q5_6cat q6_7cat EMq4 EMq8 )*randomization/chisq nopercent norow;
run;
ods rtf close;

proc print data=surv2;
run;

proc freq data=surv2;
title 'subjects who watched the traditional lecture first';
where randomization='Traditional';
   tables TSq1*EMq1/agree nopercent norow nocol;
run;
proc freq data=surv2;
title 'subjects who watched the emodule first';
where randomization='Emodule';
   tables EMq1*TSq1/agree nopercent norow nocol;
run;

